import { migrate as pgLiteMigrate } from "drizzle-orm/pglite/migrator";
import { migrate as pgMigrate } from "drizzle-orm/postgres-js/migrator";

import DatabaseInstance from "@/lib/db";

async function applyMigrations() {
  if (process.env.NODE_ENV !== "test") {
    await pgMigrate(DatabaseInstance.database as any, {
      migrationsFolder: "drizzle",
    });
  } else {
    await pgLiteMigrate(DatabaseInstance.database as any, {
      migrationsFolder: "drizzle",
    });
  }
  console.log("Migration done!");
}

export { applyMigrations };
